package com.extremelylargepackage;

import java.util.HashMap;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.extremelylargepackage.entity.Enemy;

public class StatTracker {

	private static StatTracker uniqueInstance = new StatTracker();
	private HashMap<String,Integer> _projectiles = new HashMap<String,Integer>();
	private HashMap<String,Integer> _enemies = new HashMap<String,Integer>();
	private int _shotsHit;

	private StatTracker() 
	{
		_paint = new Paint();
		_paint.setColor(Color.WHITE);
	}
	
	//TODO
	//loading implementation

	public static StatTracker getInstance()
	{
		return uniqueInstance;
	}
	
	public void RegisterKill(Enemy slainEnemy)
	{
		Integer kills = _enemies.get(slainEnemy.getName());
		if (kills == null)
		{
			kills = 0;
		}
		_enemies.put(slainEnemy.getName(),kills + 1);
	}
	
	public void RegisterShotFired(String fired)
	{
		Integer fireCount = _projectiles.get(fired);
		if (fireCount == null)
		{
			fireCount = 0;
		}
		_projectiles.put(fired, fireCount+1);
	}
	
	public void RegisterShotHit()
	{
		_shotsHit++;
	}
	
	public void RegisterLevelComplete()
	{

	}
	
	public void RegisterLevelFailed()
	{

	}
	
	private int getTotal(HashMap<?,Integer> map)
	{
		int total = 0;
		for(Integer count : map.values())
		{
			total += count;
		}
		return total;
	}
	
	public int getTotalKills()
	{
		return getTotal(_enemies);
	}
	
	public int getShotsFired()
	{
		return getTotal(_projectiles);
	}
	
	public int getTotalShotsHit()
	{
		return _shotsHit;
	}
	
	private Paint _paint;
	
	public void drawOverlay(Canvas c)
	{
		c.drawText("Kills: " + getTotalKills(), GameResources.SCREEN_WIDTH - 50 , 15, _paint);
		c.drawText("Fire: " + getShotsFired(), GameResources.SCREEN_WIDTH - 50 , 30, _paint);
		c.drawText("Hit: " + getTotalShotsHit(), GameResources.SCREEN_WIDTH - 50 , 45, _paint);
	}
}
